package com.library.service;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.library.domain.pojo.LendRecord;
import com.library.domain.vo.LendRecordVo;
import com.library.mapper.LendRecordMapper;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author : 凉小天
 * @date : 2021/7/1 10:56
 */
@Service("lendRecordService")
public class LendRecordServiceImpl extends ServiceImpl<LendRecordMapper, LendRecord>implements LendRecordService {

    /**
     * 分页查询借阅记录
     * @param page
     * @param username
     * @param bookName
     * @param readerId
     * @return
     */

    @Override
    public Map<String, Object> page(Page<LendRecord> page, String username, String bookName, Long readerId) {
        long skip = (page.getCurrent() - 1) * page.getSize();
        long size = page.getSize();

        List<LendRecordVo> list = this.baseMapper.selectAll(skip,size,username,bookName,readerId);
        Integer total = this.baseMapper.selectCount(null);
        Map<String ,Object> map = new HashMap<>();
        map.put("list",list);
        map.put("total",total);
        return map;
    }
}
